
package com.jims.master.modules.doctor.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.doctor.dao.ClinicOrdersCostDao;
import com.jims.master.modules.doctor.entity.ClinicOrdersCost;
import com.jims.master.modules.operation.entity.OperationApply;
import com.jims.master.modules.operation.entity.OperationDict;
import com.jims.master.modules.operation.entity.OperationNameApply;
import com.jims.master.modules.operation.service.OperationDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 门诊项目明细Service
 * @author CTQ
 * @version 2017-03-13
 */
@Service
@Transactional(readOnly = true)
public class ClinicOrdersCostService extends CrudService<ClinicOrdersCostDao, ClinicOrdersCost> {
	@Autowired
	OperationDictService operationDictService;
	public ClinicOrdersCost get(String id) {
		return super.get(id);
	}
	
	public List<ClinicOrdersCost> findList(ClinicOrdersCost clinicOrdersCost) {
		return super.findList(clinicOrdersCost);
	}
	
	public Page<ClinicOrdersCost> findPage(Page<ClinicOrdersCost> page, ClinicOrdersCost clinicOrdersCost) {
		return super.findPage(page, clinicOrdersCost);
	}
	
	@Transactional(readOnly = false)
	public int save(ClinicOrdersCost clinicOrdersCost) {
		return super.save(clinicOrdersCost);
	}

	/**
	 * 根据医嘱信息删除医嘱明细
	 * @param ordersId
	 * @return
	 * @author CTQ
	 */
	@Transactional(readOnly = false)
	public int delByOrderId(String ordersId) {
		return dao.delByOrderId(ordersId);
	}

	/**
	 * 手术项目收费明细
	 * @param operationApply
	 * @return
	 */
	@Transactional(readOnly = false)
	public void saveOperationApplyCostItems(OperationApply operationApply,String ordersId){
		List<OperationNameApply> list=operationApply.getOperationNameApplys();
		int num=0;
		if(list.size()>0){
			for(OperationNameApply operationNameApply:list){
				ClinicOrdersCost clinicOrdersCost=new ClinicOrdersCost();
				clinicOrdersCost.setPatientId(operationApply.getPatientId());
				clinicOrdersCost.setItemClass("F");
				clinicOrdersCost.setClinicId(operationApply.getClinicId());
				clinicOrdersCost.setOrgId(operationApply.getOrgId());
				clinicOrdersCost.setOrdersId(ordersId);
				clinicOrdersCost.setItemName(operationNameApply.getOperationName());
				clinicOrdersCost.setItemCode(operationNameApply.getOperationCode());
				OperationDict operationDict=operationDictService.findPriceByDict(operationNameApply.getOperationId());
				clinicOrdersCost.setPrice(operationDict.getPrice());
				clinicOrdersCost.setPriceId(operationDict.getPriceId());
				clinicOrdersCost.setNum(1.0);
				clinicOrdersCost.setCosts(operationDict.getPrice());
				clinicOrdersCost.setSpec("/");
				clinicOrdersCost.setUnit("次");
				clinicOrdersCost.setClassOnReckoning("G01");        // 核算项目分类
				clinicOrdersCost.setSubjCode("G01");        // 会计科目
				clinicOrdersCost.preInsert();
				dao.insert(clinicOrdersCost);
			}
		}
	}
}